package com.htc.model.utils;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;

import com.htc.common.ActionEvent;
import com.htc.constants.Constants;
import com.htc.controller.WellnessOverviewController;
import com.htc.dlc.fragment.FragmentWellnessOverview;
import com.htc.model.dto.WellnessOverviewDTO;

public class WellnewssOverviewModel {
	private ActionEvent actionEvent;
	public static WellnewssOverviewModel instance;

	public static WellnewssOverviewModel getInstance() {
		if (instance == null)
			instance = new WellnewssOverviewModel();
		return instance;
	}

	public void handleControllerEvent(ActionEvent e) {
		this.actionEvent = e;
		switch (e.action) {
		case Constants.GET_WELL_OVERVIEW:
			ArrayList<WellnessOverviewDTO> news = getAllwellnessOverview((Object) e.sender);
			e.viewData = news;
			WellnessOverviewController.getInstance().handleModelViewEvent(e);
			break;

		default:
			break;
		}
	}

	public ArrayList<WellnessOverviewDTO> getAllwellnessOverview(Object ob) {
		FragmentWellnessOverview ab = (FragmentWellnessOverview) ob;
		Context ctx = ab.getActivity().getApplicationContext();
		ArrayList<WellnessOverviewDTO> arrData = new ArrayList<WellnessOverviewDTO>();
		String sql = "SELECT * FROM fitness_class class, fitness_schedule sche where sche.fitness_schedule_class_id = class.fitness_class_id";
		DBHelper db = new DBHelper(ctx);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			WellnessOverviewDTO model = new WellnessOverviewDTO();
			model.setWellnessclassId(c.getString(c
					.getColumnIndex("fitness_class_id")));
			model.setWellnessoverviewtitle(c.getString(c
					.getColumnIndex("fitness_class_name")));
			model.setWellnessoverviewtitleAr(c.getString(c
					.getColumnIndex("fitness_class_name_ar")));
			model.setWellnessoverviewDescription(c.getString(c
					.getColumnIndex("fitness_class_description")));
			model.setWellnessoverviewDescriptionAr(c.getString(c
					.getColumnIndex("fitness_class_description_ar")));
			model.setWellnessoverviewicon(c.getString(c
					.getColumnIndex("fitness_class_image")));
			model.setWellnessPriority(c.getString(c.getColumnIndex("priority")));
			model.setWellnessGroupId(c.getString(c
					.getColumnIndex("fitness_class_group_id")));
			model.setWellnessoverviewday(c.getString(c
					.getColumnIndex("fitness_schedule_day")));
			model.setWellnessoverviewtime(c.getString(c
					.getColumnIndex("fitness_schedule_start_time")));
			arrData.add(model);

		}
		c.close();
		db.close();
		return arrData;
	}
	

	public ArrayList<Object> getAllOverview(String paramString, Context context) {
		ArrayList<Object> arrData = new ArrayList<Object>();
		String sql = "SELECT * FROM fitness_class WHERE fitness_class_group_id ='"
				+ paramString + "'";
		DBHelper db = DBHelper.getInstance(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			WellnessOverviewDTO model = new WellnessOverviewDTO();
			model.setWellnessclassId(c.getString(c
					.getColumnIndex("fitness_class_id")));
			model.setWellnessoverviewtitle(c.getString(c
					.getColumnIndex("fitness_class_name")));
			model.setWellnessoverviewtitleAr(c.getString(c
					.getColumnIndex("fitness_class_name_ar")));
			model.setWellnessoverviewDescription(c.getString(c
					.getColumnIndex("fitness_class_description")));
			model.setWellnessoverviewDescriptionAr(c.getString(c
					.getColumnIndex("fitness_class_description_ar")));
			model.setWellnessoverviewicon(c.getString(c
					.getColumnIndex("fitness_class_image")));
			model.setWellnessPriority(c.getString(c.getColumnIndex("priority")));
			model.setWellnessGroupId(c.getString(c
					.getColumnIndex("fitness_class_group_id")));
			arrData.add(model);
		}
		c.close();
		db.close();
		return arrData;
	}

	public ArrayList<Object> getAllwellnessOverview1(Object ob) {
		FragmentWellnessOverview ab = (FragmentWellnessOverview) ob;
		Context ctx = ab.getActivity().getApplicationContext();
		ArrayList<Object> arrData = new ArrayList<Object>();
		String sql = "SELECT * FROM fitness_class class, fitness_schedule sche where sche.fitness_schedule_class_id = class.fitness_class_id";
		DBHelper db = new DBHelper(ctx);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			WellnessOverviewDTO model = new WellnessOverviewDTO();
			model.setWellnessclassId(c.getString(c
					.getColumnIndex("fitness_class_id")));
			model.setWellnessoverviewtitle(c.getString(c
					.getColumnIndex("fitness_class_name")));
			model.setWellnessoverviewtitleAr(c.getString(c
					.getColumnIndex("fitness_class_name_ar")));
			model.setWellnessoverviewDescription(c.getString(c
					.getColumnIndex("fitness_class_description")));
			model.setWellnessoverviewDescriptionAr(c.getString(c
					.getColumnIndex("fitness_class_description_ar")));
			model.setWellnessoverviewicon(c.getString(c
					.getColumnIndex("fitness_class_image")));
			model.setWellnessPriority(c.getString(c.getColumnIndex("priority")));
			model.setWellnessGroupId(c.getString(c
					.getColumnIndex("fitness_class_group_id")));
			model.setWellnessoverviewday(c.getString(c
					.getColumnIndex("fitness_schedule_day")));
			model.setWellnessoverviewtime(c.getString(c
					.getColumnIndex("fitness_schedule_start_time")));
			arrData.add(model);

		}
		c.close();
		db.close();
		return arrData;
	}
}
